const fs = require('fs');

exports.pathExist = (path) => {
    try {
        return fs.existsSync(path);
    } catch (error) {
        console.error(error.message);
        throw new Error(`create dir ${path} failed message: ${error.message}`);
    }
};

exports.createDir = (path) => {
    try {
        const dirExist = fs.existsSync(path);
        if (!dirExist) {
            fs.mkdirSync(path);
        }
    } catch (error) {
        console.error(error.message);
        throw new Error(`create dir ${path} failed message: ${error.message}`);
    }
};

exports.deleteDir = (path) => {
    try {
        fs.rmdirSync(path);
    } catch (error) {
        console.error(error.message);
        throw new Error(`delete dir ${path} failed message: ${error.message}`);
    }
};

exports.deleteFile = (path) => {
    try {
        fs.unlinkSync(path);
    } catch (error) {
        console.error(error.message);
        // throw new Error(`delete file ${path} failed message: ${error.message}`);
    }
};

exports.renameFile = (oldPath, newPath) => {
    try {
        fs.renameSync(oldPath, newPath);
    } catch (error) {
        console.error(error.message);
        // throw new Error(`rename file ${oldPath} to ${newPath} failed message: ${error.message}`);
    }
};
exports.readDir = (path) => {
    try {
        return fs.readdirSync(path);
    } catch (error) {
        console.error(error.message);
        // throw new Error(`rename file ${oldPath} to ${newPath} failed message: ${error.message}`);
    }
};